package com.zkingsoft.actions.admin.web;

import java.util.Dictionary;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zkingsoft.anotations.RemoveRequestToken;
import com.zkingsoft.anotations.SaveRequestToken;
import com.zkingsoft.authority.Authority;
import com.zkingsoft.authority.MatrixAdapter;
import com.zkingsoft.constance.BusinessConstance;
import com.zkingsoft.constraint.BaseController;
import com.zkingsoft.model.bus.BusCatalog;
import com.zkingsoft.pojo.AjaxResult;
import com.zkingsoft.pojo.PaginationVO;
import com.zkingsoft.services.bus.BusCatalogService;
import com.zkingsoft.util.WebUtil;

/**
 * This field was generated by Zking.software.Codegen.
 * @date 2016-11-28 15:35
 */
@Controller
@RequestMapping(value = "admin/webTypeNav")
public class WebNavTypeController extends BaseController{

	@Resource
	private BusCatalogService busCatalogService;
	
	@Resource(name="authorityAdapter")
	private Authority  authorityAdapter;
	
	
	
	//记录编辑前的值Before_Edit_Value
	public static final String BEV="WebTypeNav_BEV";
	
	public static final String fnCode = "navType";
	public static final String search = fnCode + ":search";
	public static final String edit = fnCode + ":edit";
	public static final String del = fnCode + ":del";
	public static final String add = fnCode + ":add";
	
	/**
	 * 列表显示
	 */
	@RequestMapping(value = "/showList")
	public @ResponseBody AjaxResult showList(BusCatalog buscatalog, PaginationVO pageVo) {
		authorityAdapter.isBtnPermitted(search);
		buscatalog.setCataType(BusinessConstance.NAV_TYPE_NAME);
		return showList(busCatalogService, buscatalog, pageVo);
	}
   	
	/**
	 * 新增或者修改页面
	 */   
	@RemoveRequestToken	
   	@RequestMapping(value = "/addOrModify")
	public @ResponseBody AjaxResult addOrModify(BusCatalog buscatalog) {
		if (buscatalog.getCataId() != null) {
	   		authorityAdapter.isBtnPermitted(edit);
	   		AjaxResult result=modify(busCatalogService, WebUtil.getSessionAttribute(this.BEV), buscatalog, "导航栏类型");
			WebUtil.removeSessionAttribute(this.BEV);
			return  result;
		} else {
			authorityAdapter.isBtnPermitted(add);
			buscatalog.setCataType(BusinessConstance.NAV_TYPE_NAME);
			return add(busCatalogService, buscatalog, "导航栏类型");
		}
	}
	
   	/**
	 * 进入修改界面
	 */   
	@SaveRequestToken
   	@RequestMapping(value = "/editForm")
	public String editForm(Long id) {
		authorityAdapter.isBtnPermitted(edit);
		BusCatalog buscatalog;
		if (id != null) {
			buscatalog = busCatalogService.findById(id);
			WebUtil.getRequest().setAttribute("obj", buscatalog);
			WebUtil.setSessionAttribute(this.BEV, buscatalog);
		}
		return "admin/web/navType-form";
	}
   	
   	
   	/**
	 * 删除
	 */  
 	@RequestMapping(value = "/del")
	public @ResponseBody AjaxResult del(String keys) {
		authorityAdapter.isBtnPermitted(del);
		return remove(busCatalogService, keys);
	}
 	
 	/**
 	 * 查找所有的导航栏分类
 	 */
 	@RequestMapping(value="/showParentType")
 	public @ResponseBody AjaxResult showParentType(BusCatalog buscatalog){
 		//导航栏分类的类型名称
 		buscatalog.setCataType(BusinessConstance.NAV_TYPE_NAME);
 		List<BusCatalog> busCatalogList = busCatalogService.findByModel(buscatalog);
 		return new AjaxResult(AjaxResult.STATUS_OK, null, null, busCatalogList, null);
 	}
}
